package com.wbs.shop.nuby.commom;

import android.content.Context;
import android.content.SharedPreferences;


/**
 * Created by vicky on 2016/11/4.
 */
public class PreferencesOperation {
    private SharedPreferences mSettings;
    private static PreferencesOperation mInstance = null;

    private PreferencesOperation(Context context) {
        mSettings = context.getSharedPreferences(Key.PREFERENCES_NAME, Context.MODE_PRIVATE);
    }

    public static PreferencesOperation getInstance(Context context) {
        if (null == mInstance) {
            synchronized (PreferencesOperation.class) {
                if (null == mInstance) {
                    mInstance = new PreferencesOperation(context.getApplicationContext());
                }
            }
        }
        return mInstance;
    }

    public String getString(String key) {
        return mSettings.getString(key, "");
    }

    public int getInt(String key, int value) {
        return mSettings.getInt(key, value);
    }

    public void setString(String key, String value) {
        SharedPreferences.Editor editor = mSettings.edit();
        editor.putString(key, value);
        editor.commit();
    }

    public void setInt(String key, int value) {
        SharedPreferences.Editor editor = mSettings.edit();
        editor.putInt(key, value);
        editor.commit();
    }

    public boolean getBoolean(String key, boolean defValue) {
        return mSettings.getBoolean(key, defValue);
    }

    public boolean getBoolean(String key) {
        return mSettings.getBoolean(key, false);
    }

    public void setBoolean(String key, boolean value) {
        SharedPreferences.Editor editor = mSettings.edit();
        editor.putBoolean(key, value);
        editor.commit();
    }

}
